package com.leo.ibatis.demo.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.leo.ibatis.demo.domain.Account;

public class AccountValidator implements Validator {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return Account.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userid", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "addr1", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "city", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "state", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "zip", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "country", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "required");
	}

}
